using System;
using System.Collections.Generic;
using System.Text;
using LispInterpretor.HelperClasses;
using LispInterpretor.DataTypes;

namespace LispInterpretor.InBuiltProcedures
{
    public class Divide : Procedure
    {
        private const string NONE_NUMBER_ERROR = "Can't divide none number types.";

        public override object Apply(params object[] args)
        {
            Check.IsTrue(args.Length >= 2, "Division requires at least two arguments.");

            Check.IsTrue(args[0] is Number, NONE_NUMBER_ERROR);
            Number accumulator = (Number) args[0];

            for (int i = 1; i < args.Length; i++)
            {
                Check.IsTrue(args[i] is Number, NONE_NUMBER_ERROR);
                accumulator = Number.Divide(accumulator, (Number) args[i]);
            }

            return accumulator;
        }
    }
}
